#!/bin/sh

# Lemonbar configurations by SBCT;
# https://notabug.org/sabactani/dotfiles

Workspace(){
      wm=$(wmctrl -d | awk '{print $2$NF}' ORS=" "  | sed 's/-//g'|\
      sed 's/1/I/'|\
      sed 's/2/II/'|\
      sed 's/3/III/'|\
      sed 's/4/IV/'|\
      sed 's/5/V/'|\
      sed 's/6/VI/'|\
      sed 's/7/VII/'|\
      sed 's/8/VIII/'|\
      sed 's/9/IX/'|\
      sed 's/10/X/')

      echo -n "$wm"
}

Memory(){
      mem=$(free -mh | awk '{print $3}' | sed -n '2p' | sed "s/Gi/ GiB/")
      echo -en "\ue021 $mem"
} 

Clock() { 
      clock=$(date "+%d/%m/%Y %H:%M:%S")
      echo -en "\ue266 $clock"
}

Disk() {
      space=$(grep /dev/root <<< "$(df -h)" | awk  '{print $2 " / " $4 " " "("$5")"}')
      echo -en "\ue1bb $space"
}

Window(){
      title=$(xtitle)
      echo -n "$title"    
}

CPU(){
       (grep "Cpu(s)" <<< "$(top -bn1)" | \
       sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
       awk '{print  100 - $1"%"}') 
}

MPD(){
if [ $(mpc | head -1 | wc -m) -ge 69 ];
then
song=$(echo '')
else
song=$(mpc | head -1)
fi

if [ "$song" = "$(mpc | head -1)" ]; 
then
echo -n "\ue1a6 $song"
else
echo -n "$song"
fi      
}


while :; do
      echo -e "%{A5:i3-msg workspace next:}%{A4:i3-msg workspace previous:}$(Workspace)%{A}%{A} %{A1:mpc toggle:}%{A4:mpc volume +3:}%{A5:mpc volume -3:}$(MPD)%{A}%{A}%{A} %{c} $(Window) %{r} $(CPU) | $(Disk) | $(Memory) | $(Clock)"
      sleep 0.8 
done |\

lemonbar -p -g 1920x25 -o 1 -f 'xos4 Terminus:size=10' -o -2 -f '-wuncon-siji-medium-r-normal--10-100-75-75-c-80-iso10646-1' -B '#1a1a1a' -F '#B0B0B0' | sh  
